package com.yingli.component.activity.transfer;

import android.annotation.TargetApi;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.yingli.component.R;
import com.yingli.component.activity.transfer.entity.Book;
import com.yingli.component.activity.transfer.entity.User;

public class SecondActivity extends AppCompatActivity {

    private TextView tvData;
    @Override
    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_second);
        tvData = findViewById(R.id.tv_data);
        Intent intent = getIntent();
        if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.LOLLIPOP) {
//        int data = intent.getIntExtra("value",-1);
        }
        //接收类型必须与上一页面传递的类型一致
        String data = intent.getStringExtra("value");
        //注意，不能设置int类型的数据
        User user = (User) intent.getSerializableExtra("user");
//        tvData.setText(String.valueOf(data));
//        tvData.setText(user.toString());
        //接收一个Parcelable类型的对象
        Book book= intent.getParcelableExtra("book");
        tvData.setText(book.toString());
        findViewById(R.id.btn_transfer).setOnClickListener(v->{
            book.setPrice(158.0);
            //携带数据返回上一界面
            Intent i = new Intent();
            i.putExtra("b",book);
            setResult(RESULT_OK,i);
            finish();
        });

    }
}
